package text.adventure.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class GameData {

	List<GameObject> general;
	Map<Integer, LinkedList<Integer>> chapters;
	Map<Integer, LinkedList<GameObject>> rooms;
	int currentChapter;
	int currentRoom;
	
	public GameData() {
		this.general = new ArrayList<GameObject>();
		this.chapters = new HashMap<Integer, LinkedList<Integer>>();
	}
	
	public void addGeneralObject(GameObject gobj) {
		this.general.add(gobj);
	}
	
	public GameObject getGeneralObject(int index) {
		return general.get(index);
	}
	
	public GameObject getGeneralObject(String name) {
		for (GameObject go : general) {
			if (go.getId().equals(name)) {
				return go;
			}
		}
		return null;
	}
	
	public List<GameObject> getGeneralObjects(String[] name) {
		List<GameObject> result = new ArrayList<GameObject>();
		for (String n : name) {
			result.add(getGeneralObject(n));
		}
		return result;
	}
	
	public List<GameObject> getGeneralObjects() {
		return general;
	}
	
	public void addChapter(int chapterId) {
		this.chapters.put(chapterId, new LinkedList<Integer>());
	}
	
	public void addRoom(int roomId) {
		this.rooms.put(roomId, new LinkedList<GameObject>());
		setCurrentRoom(roomId);
	}
	
	public int getCurrentChapter() {
		return currentChapter;
	}
	
	public int getCurrentRoom() {
		return currentRoom;
	}
	
	public List<GameObject> getFromRoomId(int id) {
		return rooms.get(id);
	}
	
	public void setCurrentChapter(int chapterId) {
		currentChapter = chapterId;
	}
	
	public void setCurrentRoom(int roomId) {
		currentRoom = roomId;
	}
	
	public void addToCurrentChapter(int room) {
		this.chapters.get(currentChapter).add(room);
	}
	
	public void addToCurrentRoom(GameObject gobj) {
		this.rooms.get(currentRoom).add(gobj);
	}
	
	public List<Integer> getChapter(int index) {
		return this.chapters.get(index);
	}
}
